package com.xzy.service;

import com.xzy.pojo.UserEmail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;

@Service
public class SendMail {
    @Autowired
    JavaMailSenderImpl mailSender;

    public void sendMail(UserEmail userEmail) throws MessagingException {
        MimeMessage mimeMessage =mailSender.createMimeMessage();
        MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
        helper.setSubject("亲爱的用户:"+userEmail.getUsername()+"您好");
        helper.setText("感谢您对于锡纸炎投票系统支持,送您一张精美陈冠希照片为礼物",true);
        helper.addAttachment("陈冠希.jpg", new File("C:\\Users\\萧炎\\Desktop\\edc.jpg"));
        helper.setTo(userEmail.getEmail());
        helper.setFrom("2339806461@qq.com");
        mailSender.send(mimeMessage);
    }
}
